<%--
  Created by IntelliJ IDEA.
  User: 王辉
  Date: 2022/5/10
  Time: 11:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<% request.setCharacterEncoding("UTF-8");%>
<html>
<head>
    <title>修改名片</title>
</head>
<body>
<%
    String driverName="com.mysql.cj.jdbc.Driver";
    String username = "root";
    String password = "123456";
    String url = "jdbc:mysql://localhost:3306/t_card?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false";
    Class.forName(driverName);
    Connection conn = DriverManager.getConnection(url,username,password);
    String sql = "select * from cuser where uid = ? and isdeleted = 0";
    String sql2 = "select id from user where username = ?";
    PreparedStatement pstmt = conn.prepareStatement(sql);
    PreparedStatement pstmt2 = conn.prepareStatement(sql2);
    String userName = (String) session.getAttribute("username");
    pstmt2.setString(1,userName);
    ResultSet rs1 = pstmt2.executeQuery();
    String uid = "";
    while (rs1.next()){
        uid = rs1.getString("id");
    }
    pstmt.setString(1,uid);
    ResultSet rs = pstmt.executeQuery();
    List list = new ArrayList<>();
    while (rs.next()){
        list.add(rs.getInt("cid"));
        list.add(rs.getString("cname"));
        list.add(rs.getString("csex"));
        list.add(rs.getString("cphone"));
        list.add(rs.getString("cemail"));
    }
%>

<table border="1px" align="center">
    <tr>
        <td>序号</td>
        <td>备注</td>
        <td>性别</td>
        <td>手机号</td>
        <td>邮箱</td>
    </tr>

    <div align="center">
        <%
            for(int i=0;i<list.size();i=i+5)
            {
        %>
        <tr align="center">
            <td><%=list.get(i)%></td>
            <td><%=list.get(i+1)%></td>
            <td><%=list.get(i+2)%></td>
            <td><%=list.get(i+3)%></td>
            <td><%=list.get(i+4)%></td>
        </tr><br>
    </div>

    <%
        }
    %>
</table><br><br><br>
<div align="center">
<form action="updateing.jsp" method="post">
    请输入要修改名片的序号:<input type="text" name="cid"><br>
    <input type="submit" value="提交">
</form>
    <br><br><br><a href="index.jsp" style="color: crimson">返回主页</a>
</div>
</body>
</html>
